package com.sgcc.fj.pmos.e_fj_home.adapter;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.fj.pmos.common.utils.JsonToMap;
import com.sgcc.fj.pmos.e_fj_home.bean.FileBean;
import com.sgcc.fj.pmos.e_fj_home.bean.SBDSBJXJHZHBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SBDSBJXJHAdapter extends BaseQuickAdapter<SBDSBJXJHZHBean, BaseViewHolder> {

    private Activity mContext;
    private TextView mTvLeft;
    private TextView mTvRight;

    public SBDSBJXJHAdapter(Activity context) {
        super(R.layout.item_sbdsbjxjh);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, SBDSBJXJHZHBean bean) {
        LinearLayout relativeLayout = baseViewHolder.getView(R.id.ll_content);
        relativeLayout.removeAllViews();
        List<SBDSBJXJHZHBean.DataBean> listBean = bean.getData();
        for (int i = 0; i < listBean.size(); i++) {
            View head_view = mContext.getLayoutInflater().inflate(R.layout.item_content_sbdsbjxjh, null);
            mTvLeft = (TextView) head_view.findViewById(R.id.tv_left);
            mTvRight = (TextView) head_view.findViewById(R.id.tv_right);
            mTvLeft.setText(listBean.get(i).getColTitle());
            mTvRight.setText(getStr(listBean.get(i).getColName(), bean));
            relativeLayout.addView(head_view);
        }
    }

    private String getStr(String keyStr, SBDSBJXJHZHBean bean) {
        String result = "";
        Gson gson = new Gson();
        String json = gson.toJson(bean);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap = gson.fromJson(json, resultMap.getClass());
        Set<String> keySet = resultMap.keySet();
        //遍历键的集合，得到每一个键
        for (String key : keySet) {
            //由键找值
            if (keyStr.equals(key)) {
                if (keyStr.toLowerCase().contains("time")) {
                    result = DateUtils.getStrng_to_Times_ymdhms((String) resultMap.get(key));
                } else {
                    result = (String) resultMap.get(key);
                }
                break;
            }
        }
        return result;
    }
}


